package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

import service.impl.CloseConnections;

public class LearningMethodDAO {
	static Connection currentConnection = null;
	static ResultSet rs = null;

	public static Map<Long, String> getAll() {
		PreparedStatement statement = null;
		Map<Long, String> methods = new HashMap<Long, String>();

		try {
			// connect to DB
			currentConnection = ConnectionManager.getConnection();
			String sql = "select * from learning_method";
			statement = currentConnection.prepareStatement(sql);
			rs = statement.executeQuery();
			while (rs.next()) {
				Long methodId = rs.getLong("id");
				String methodType = rs.getString("type");
				methods.put(methodId, methodType);
			}

		} catch (Exception e) {
			System.out.println("Exception in connection!: " + e);
		} finally {
			CloseConnections.closeAll(rs, statement, currentConnection);
		}
		return methods;
	}

}
